﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using DiscoveryLogic.Analytics.BusinessLogic.Entities;
using DiscoveryLogic.Analytics.BusinessLogic.Networks;
using DiscoveryLogic.Analytics.BusinessLogic.Rules;
using DiscoveryLogic.Analytics.DataObjects;
using DiscoveryLogic.Analytics.DataObjects.Networks;
using DiscoveryLogic.Analytics.DataObjects.Rules;
using DiscoveryLogic.Analytics.DataObjects.Visuals;
using DiscoveryLogic.Common.Utilities;

namespace DiscoveryLogic.Analytics.BusinessLogic
{
    public static class MyData
    {
        public static ObservableCollection<EntitySetsByType> AllEntitySets=
            new ObservableCollection<EntitySetsByType>();
        public static ObservableCollection<RulesByType> AllRules=
            new ObservableCollection<RulesByType>();
        public static ObservableCollection<NetworksBySource> AllNetworks=
            new ObservableCollection<NetworksBySource>();

        public static void ReadAllNetworks()
        {
            AllNetworks.Clear();
            List<Network> networks =
                NetworkManager.GetNetworks(EntityType.Grants);
            if (networks != null && networks.Count > 0)
                AllNetworks.Add(new NetworksBySource("Grants", networks));

            networks =
                NetworkManager.GetNetworks(EntityType.Organizations);
            if (networks != null && networks.Count > 0)
                AllNetworks.Add(new NetworksBySource("Organizations", networks));

            networks =
                NetworkManager.GetNetworks(EntityType.Persons);
            if (networks != null && networks.Count > 0)
                AllNetworks.Add(new NetworksBySource("Persons", networks));

            networks =
                NetworkManager.GetNetworks(EntityType.Publications);
            if (networks != null && networks.Count > 0)
                AllNetworks.Add(new NetworksBySource("Publications", networks));

            networks =
                NetworkManager.GetNetworks(EntityType.Document);
            if (networks != null && networks.Count > 0)
                AllNetworks.Add(new NetworksBySource("Documents", networks));

            networks =
                NetworkManager.GetNetworks(EntityType.Subject);
            if (networks != null && networks.Count > 0)
                AllNetworks.Add(new NetworksBySource("Subjects", networks));

            networks =
                NetworkManager.GetNetworks(EntityType.Misc);
            if(networks !=null && networks.Count>0)
                AllNetworks.Add(new NetworksBySource("Misc", networks));
        }

        public static void ReadAllEntitySets()
        {
            AllEntitySets.Clear();
            List<EntityDataSet> grants =
                DataSetManager.GetEntityDataSets(EntityType.Grants);
            if(grants !=null && grants.Count>0)
                AllEntitySets.Add(new EntitySetsByType(EntityType.Grants.ToString(), grants));

            List<EntityDataSet> orgs =
                DataSetManager.GetEntityDataSets(EntityType.Organizations);
            if (orgs != null && orgs.Count>0)
                AllEntitySets.Add(new EntitySetsByType(EntityType.Organizations.ToString(), orgs));

            List<EntityDataSet> persons =
                DataSetManager.GetEntityDataSets(EntityType.Persons);
            if (persons != null && persons.Count>0)
                AllEntitySets.Add(new EntitySetsByType(EntityType.Persons.ToString(), persons));

            List<EntityDataSet> pubs =
                DataSetManager.GetEntityDataSets(EntityType.Publications);
            if (pubs != null && pubs.Count>0)
                AllEntitySets.Add(new EntitySetsByType(EntityType.Publications.ToString(), pubs));

            List<EntityDataSet> docs =
                DataSetManager.GetEntityDataSets(EntityType.Document);
            if(docs !=null && docs.Count>0)
                AllEntitySets.Add(new EntitySetsByType(EntityType.Document.ToString(), docs));

            List<EntityDataSet> subjs =
                DataSetManager.GetEntityDataSets(EntityType.Subject);
            if(subjs !=null && subjs.Count>0)
                AllEntitySets.Add(new EntitySetsByType(EntityType.Subject.ToString(), subjs));
        }

        public static void ReadAllRules()
        {
            AllRules.Clear();
            // import
            List<RuleBase> importRules = RuleManager.GetRulesByType(RuleType.Import, "../images/excel.ico");
            if (importRules != null && importRules.Count > 0)
                AllRules.Add(new RulesByType(RuleType.Import, importRules));
            
            // link 
            List<RuleBase> linkRules = RuleManager.GetRulesByType(RuleType.Link, "../images/link.ico");
            if (linkRules != null && linkRules.Count > 0)
                AllRules.Add(new RulesByType(RuleType.Link, linkRules));
            
            // dedup
            List<RuleBase> dedupRules = RuleManager.GetRulesByType(RuleType.Dedup, "../images/dedup.ico");
            if (dedupRules != null && dedupRules.Count > 0)
                AllRules.Add(new RulesByType(RuleType.Dedup, dedupRules));

            // cluster
            List<RuleBase> clusterRules = RuleManager.GetRulesByType(RuleType.Cluster, EntityIcons.ClusterRuleIcon);
            if(clusterRules !=null && clusterRules.Count>0)
                AllRules.Add(new RulesByType(RuleType.Cluster, clusterRules));
        }
    }
}
